| Conditions | 25 |
| Paths | > 20000 |
| Total Lines | 208 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like window.egw_LAB.wait often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | /** |
||
| 158 | window.egw_LAB.script(include).wait(function() |
||
| 159 | { |
||
| 160 | // We need to override the globalEval to mitigate potential execution of |
||
| 161 | // script tag. This issue is relevant to jQuery 1.12.4, we need to check |
||
| 162 | // if we still need this after upgrading jQuery. |
||
| 163 | jQuery.extend({ |
||
| 164 | globalEval:function(data){} |
||
| 165 | }); |
||
| 166 | |||
| 167 | // call egw.link_handler, if attr specified |
||
| 168 | var egw_redirect = egw_script.getAttribute('data-egw-redirect'); |
||
| 169 | if (egw_redirect) |
||
| 170 | { |
||
| 171 | // set sidebox for tabed templates, we need to set it now, as framework will not resent it! |
||
| 172 | var sidebox = egw_script.getAttribute('data-setSidebox'); |
||
| 173 | if (window.framework && sidebox) |
||
| 174 | { |
||
| 175 | window.framework.setSidebox.apply(window.framework, JSON.parse(sidebox)); |
||
| 176 | } |
||
| 177 | egw_redirect = JSON.parse(egw_redirect); |
||
| 178 | egw.link_handler.apply(egw, egw_redirect); |
||
| 179 | return; // do NOT execute any further code, as IE(11) will give errors because framework already redirects |
||
| 180 | } |
||
| 181 | |||
| 182 | // call egw_refresh on opener, if attr specified |
||
| 183 | var refresh_opener = egw_script.getAttribute('data-refresh-opener'); |
||
| 184 | if (refresh_opener && window.opener) |
||
| 185 | { |
||
| 186 | refresh_opener = JSON.parse(refresh_opener) || {}; |
||
| 187 | window.opener.egw(window.opener).refresh.apply(egw(window.opener), refresh_opener); |
||
| 188 | } |
||
| 189 | |||
| 190 | // close window / call window.close(), if data-window-close is specified |
||
| 191 | var window_close = egw_script.getAttribute('data-window-close'); |
||
| 192 | if (window_close) |
||
| 193 | { |
||
| 194 | if (typeof window_close == 'string' && window_close !== '1') |
||
| 195 | { |
||
| 196 | alert(window_close); |
||
| 197 | } |
||
| 198 | // If there's a message & opener, set it |
||
| 199 | if(window.opener && egw_script.getAttribute('data-message')) |
||
| 200 | { |
||
| 201 | egw(window.opener).message(JSON.parse(egw_script.getAttribute('data-message'))); |
||
| 202 | } |
||
| 203 | egw(window).close(); |
||
| 204 | } |
||
| 205 | |||
| 206 | // call egw.open_link, if popup attr specified |
||
| 207 | var egw_popup = egw_script.getAttribute('data-popup'); |
||
| 208 | if (egw_popup) |
||
| 209 | { |
||
| 210 | egw_popup = JSON.parse(egw_popup) || []; |
||
| 211 | egw.open_link.apply(egw, egw_popup); |
||
| 212 | } |
||
| 213 | |||
| 214 | if(typeof console != "undefined" && console.timeEnd) console.timeEnd("egw"); |
||
| 215 | var end_time = (new Date).getTime(); |
||
| 216 | var gen_time_div = jQuery('#divGenTime_'+window.egw_appName); |
||
| 217 | if (!gen_time_div.length) gen_time_div = jQuery('.pageGenTime'); |
||
| 218 | var gen_time_async = jQuery('.asyncIncludeTime').length > 0 ? jQuery('.asyncIncludeTime'): |
||
| 219 | gen_time_div.append('<span class="asyncIncludeTime"></span>').find('.asyncIncludeTime'); |
||
| 220 | gen_time_async.text(egw.lang('async includes took %1s', (end_time-start_time)/1000)); |
||
| 221 | |||
| 222 | // Make sure opener knows when we close - start a heartbeat |
||
| 223 | if((popup || window.opener) && window.name != '') |
||
| 224 | { |
||
| 225 | // Timeout is 5 seconds, but it iks only applied(egw_utils) when something asks for the window list |
||
| 226 | window.setInterval(function() { |
||
| 227 | egw().storeWindow(this.egw_appName, this); |
||
| 228 | }, 2000); |
||
| 229 | } |
||
| 230 | |||
| 231 | // instanciate app object |
||
| 232 | var appname = window.egw_appName; |
||
| 233 | if (app && typeof app[appname] != 'object' && typeof app.classes[appname] == 'function') |
||
| 234 | { |
||
| 235 | app[appname] = new app.classes[appname](); |
||
| 236 | } |
||
| 237 | |||
| 238 | // set sidebox for tabed templates |
||
| 239 | var sidebox = egw_script.getAttribute('data-setSidebox') || jQuery('#late-sidebox').attr('data-setSidebox'); |
||
| 240 | if (window.framework && sidebox && sidebox !== 'null') |
||
| 241 | { |
||
| 242 | window.framework.setSidebox.apply(window.framework, JSON.parse(sidebox)); |
||
| 243 | } |
||
| 244 | |||
| 245 | var resize_attempt = 0; |
||
| 246 | var resize_popup = function() |
||
| 247 | { |
||
| 248 | var $main_div = jQuery('#popupMainDiv'); |
||
| 249 | var $et2 = jQuery('.et2_container'); |
||
| 250 | var w = { |
||
| 251 | width: egw_getWindowInnerWidth(), |
||
| 252 | height: egw_getWindowInnerHeight() |
||
| 253 | }; |
||
| 254 | // Use et2_container for width since #popupMainDiv is full width, but we still need |
||
| 255 | // to take padding/margin into account |
||
| 256 | var delta_width = w.width - ($et2.outerWidth(true) + ($main_div.outerWidth(true) - $main_div.width())); |
||
| 257 | var delta_height = w.height - ($et2.outerHeight(true) + ($main_div.outerHeight(true) - $main_div.height())); |
||
| 258 | |||
| 259 | // Don't let the window gets horizental scrollbar |
||
| 260 | var scrollWidth = document.body.scrollWidth - document.body.clientWidth; |
||
| 261 | if (scrollWidth > 0 && scrollWidth + egw_getWindowOuterWidth() < screen.availWidth) delta_width = -scrollWidth; |
||
| 262 | |||
| 263 | if (delta_height && egw_getWindowOuterHeight() >= egw.availHeight()) |
||
| 264 | { |
||
| 265 | delta_height = 0; |
||
| 266 | } |
||
| 267 | if((delta_width != 0 || delta_height != 0) && |
||
| 268 | (delta_width >2 || delta_height >2 || delta_width<-2 || delta_height < -2)) |
||
| 269 | { |
||
| 270 | |||
| 271 | if (window.framework && typeof window.framework.resize_popup != 'undefined') |
||
| 272 | { |
||
| 273 | window.framework.resize_popup($et2.outerWidth(true), $et2.outerHeight(true), window); |
||
| 274 | } |
||
| 275 | else |
||
| 276 | { |
||
| 277 | window.resizeTo(egw_getWindowOuterWidth() - delta_width+8, egw_getWindowOuterHeight() - delta_height); |
||
| 278 | } |
||
| 279 | } |
||
| 280 | // trigger a 2. resize, as one is not enough, if window is zoomed |
||
| 281 | if (delta_width && ++resize_attempt < 2) |
||
| 282 | { |
||
| 283 | window.setTimeout(resize_popup, 50); |
||
| 284 | } |
||
| 285 | else |
||
| 286 | { |
||
| 287 | resize_attempt = 0; |
||
| 288 | } |
||
| 289 | }; |
||
| 290 | |||
| 291 | // rest needs DOM to be ready |
||
| 292 | jQuery(function() { |
||
| 293 | // load etemplate2 template(s) |
||
| 294 | jQuery('form.et2_container[data-etemplate]').each(function(index, node){ |
||
| 295 | var data = JSON.parse(node.getAttribute('data-etemplate')) || {}; |
||
| 296 | var currentapp = data.data.currentapp || window.egw_appName; |
||
| 297 | if(popup || window.opener && !egwIsMobile()) |
||
| 298 | { |
||
| 299 | // Resize popup when et2 load is done |
||
| 300 | jQuery(node).on('load', function() { |
||
| 301 | window.setTimeout(resize_popup, 50); |
||
| 302 | }); |
||
| 303 | } |
||
| 304 | var et2 = new etemplate2(node, "EGroupware\\Api\\Etemplate::ajax_process_content"); |
||
| 305 | et2.load(data.name,data.url,data.data); |
||
| 306 | if (typeof data.response != 'undefined') |
||
| 307 | { |
||
| 308 | var json_request = egw(window).json(); |
||
| 309 | json_request.handleResponse({response: data.response}); |
||
| 310 | } |
||
| 311 | }); |
||
| 312 | |||
| 313 | // set app-header |
||
| 314 | if (window.framework && egw_script.getAttribute('data-app-header')) |
||
| 315 | { |
||
| 316 | egw(window).app_header(egw_script.getAttribute('data-app-header'), appname); |
||
| 317 | } |
||
| 318 | // display a message |
||
| 319 | if (egw_script.getAttribute('data-message')) |
||
| 320 | { |
||
| 321 | var params = JSON.parse(egw_script.getAttribute('data-message')) || ['']; |
||
| 322 | egw(window).message.apply(egw(window), params); |
||
| 323 | } |
||
| 324 | // hide location bar for mobile browsers |
||
| 325 | if (egw_script.getAttribute('data-mobile')) |
||
| 326 | { |
||
| 327 | window.scrollTo(0, 1); |
||
| 328 | } |
||
| 329 | try { |
||
| 330 | // Open tutorial popup with an introduction video about egroupware |
||
| 331 | if (window.framework === window.top.framework && typeof et2_dialog != 'undefined' && |
||
| 332 | !egw.preference('egw_tutorial_noautoload', 'common') && |
||
| 333 | !parseInt(document.getElementById('egw_script_id').getAttribute('data-framework-reload')) && |
||
| 334 | (!egw.config('egw_tutorial_disable', 'phpgwapi') || egw.config('egw_tutorial_disable', 'phpgwapi') == 'sidebox')) |
||
| 335 | { |
||
| 336 | // we need to wait until common translations are loaded |
||
| 337 | egw.langRequireApp(window, 'common', function() |
||
| 338 | { |
||
| 339 | var buttons = [ |
||
| 340 | {text:egw.lang("Show now"), id:"show", image: "check", default:"true"}, |
||
| 341 | {text:egw.lang("Show next login"), id:"later", image: "right"}, |
||
| 342 | {text:egw.lang("No thanks"), id:"never", image: "cancel"} |
||
| 343 | ]; |
||
| 344 | et2_dialog.show_dialog(function (_button_id) |
||
| 345 | { |
||
| 346 | if (_button_id == "show" ) |
||
| 347 | { |
||
| 348 | egw.open_link(egw.link('/index.php', 'menuaction=api.EGroupware\\Api\\Framework\\Tutorial.popup&tuid=introduction-'+egw.preference('lang')+'-0-a'),'_blank','960x580'); |
||
| 349 | } |
||
| 350 | if(_button_id != "later") |
||
| 351 | { |
||
| 352 | egw.set_preference('common', 'egw_tutorial_noautoload',true); |
||
| 353 | } |
||
| 354 | }, |
||
| 355 | egw.lang('We would like to introduce you to EGroupware by showing a short introduction video.'), |
||
| 356 | egw.lang('Introduction'), |
||
| 357 | {}, buttons, et2_dialog.QUESTION_MESSAGE, undefined, egw(window)); |
||
| 358 | }, this); |
||
| 359 | } |
||
| 360 | } |
||
| 361 | catch(e) { |
||
| 362 | // ignore SecurityError exception if top is different security context / cross-origin |
||
| 363 | } |
||
| 364 | }); |
||
| 365 | }); |
||
| 366 | |||
| 419 |